#include <iostream>
#include <pthread.h>
using namespace std;
#define NUM_THREADS 5

void *test(void *args)
{
    cout << "I am in thread " << *((int *)args) << endl;
    int status = 10 + *((int *)args);
    pthread_exit((void*)status);
}

int main()
{
    pthread_t t[NUM_THREADS];
    int list[NUM_THREADS];
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    for(int i = 0; i < NUM_THREADS; i++)
    {
        list[i] = i;
        pthread_create(&t[i], &attr, test, (void*)&(list[i]));
    }
    pthread_attr_destroy(&attr);
    void *status;
    for(int i = 0; i < NUM_THREADS; i++)
    {
        pthread_join(t[i], &status);
    }
}
